from django.shortcuts import render, HttpResponse
from base.views import get_menu
from django.contrib.auth.decorators import login_required
from clients.Client import Client
from clients.models import AmazonRefundStatisticsDetail, StoreInfo, AmazonFbaReimbursementStatistics
import json
from base.views import ComplexEncoder
from django.views.decorators.csrf import requires_csrf_token, csrf_exempt
import datetime


# Create your views here.


def show_no_info_page(request):
    menu = get_menu(request)
    return render(request, "no_info.html", {"menu": menu})


def page_404(request, exception=None):
    return render(request, '404.html', status=404)


def page_500(request, exception=None):
    return render(request, '50x.html', status=500)


@login_required
def homepage(request):
    menu = get_menu(request)
    homeinfo = Client(request.user).get_home_info()
    return render(request, 'home.html', {"menu": menu, "homeinfo": homeinfo})


def total_claim_detail(request):
    return render(request, "total_claim_detail.html")


def claim_successful_detail(request):
    return HttpResponse("索赔成功详情")


def claiming_detail(request):
    return HttpResponse("索赔中详情")


def claim_failed_detail(request):
    return HttpResponse("索赔失败详情")


def total_store_detail(request):
    return HttpResponse("所有店铺详情")


def authorized_store_detail(request):
    return HttpResponse("已授权店铺详情")


def unauthorized_store_detail(request):
    return HttpResponse("未授权店铺详情")


def overview_table(request):
    """
    home页面，数据总览表格
    :param request:
    :return:
    # 返回符合查询条件的数据，默认返回10条
    """
    page = int(request.GET.get('page', 1))
    limit = int(request.GET.get('limit', 10))
    site = str(request.GET.get('site', '')).replace(" ", "")
    shop_name = str(request.GET.get('store', '')).replace(" ", "")
    sku = str(request.GET.get('sku', '')).replace(" ", "")
    type = str(request.GET.get('type', '')).replace(" ", "")

    search_info = {
        'userid__exact': request.user.id,
        'site__in': site.split(",") if "," in site or site else site,
        'shop_name__icontains': shop_name,
        'seller_sku__icontains': sku,
        'refund_type__in': type.split(",") if "," in type or type else type,
    }
    filter_info = {k: v for k, v in search_info.items() if v}
    start_index = (page - 1) * limit
    end_index = start_index + limit

    counts = AmazonRefundStatisticsDetail.objects.filter(**filter_info).count()
    objs = AmazonRefundStatisticsDetail.objects.filter(**filter_info)[start_index:end_index]
    if objs:
        datas = [{
            "shop_name": obj.shop_name,
            "seller_sku": obj.seller_sku,
            "site": obj.get_site_display(),
            "refund_type": obj.get_refund_type_display(),
            "amazon_order_id": obj.amazon_order_id,
            "shipment_id": obj.shipment_id,
            "refund_detail": obj.refund_detail,
            "deal_status": obj.get_deal_status_display(),
            "case_id": obj.case_id,
            "refresh_time": obj.refresh_time
        } for obj in objs]

        result = {
            "code": 0,
            "msg": "查询成功",
            "count": counts,
            "data": list(datas)
        }
    else:
        result = {
            "code": -1,
            "msg": "没有数据",
            "count": 0,
            "data": []
        }

    # print(json.dumps(result, cls=ComplexEncoder))
    return HttpResponse(json.dumps(result, cls=ComplexEncoder), content_type="application/json")


def store_authorization(request):
    """
    店铺授权页面
    :param request:
    :return:
    """
    menu = get_menu(request)
    return render(request, 'store_authorization.html', {'menu': menu})


def show_authoriztion_info(request):
    """
    店铺授权数据表展示
    :param request:
    :return:
    """
    page = int(request.GET.get('page', 1))
    limit = int(request.GET.get('limit', 15))
    status = str(request.GET.get('status', '')).replace(" ", "")
    shopname = str(request.GET.get('search', '')).replace(" ", "")

    search_info = {
        "userid__exact": request.user.id,
        "status__exact": status,
        "shopname__icontains": shopname,
    }
    filter_info = {k: v for k, v in search_info.items() if v}
    start_index = (page - 1) * limit
    end_index = start_index + limit

    counts = StoreInfo.objects.filter(**filter_info).count()
    objs = StoreInfo.objects.filter(**filter_info)[start_index:end_index]
    if objs:
        datas = [{
            "shopname": obj.shopname,
            "sellerid": obj.sellerid,
            "site": obj.get_site_display(),  # 站点名称
            "site_abbr": str(obj.site).lower(),  # 站点简称
            "status": obj.status,
            "authorizationd_datetime": obj.authorizationd_datetime
        } for obj in objs]
        result = {
            "code": 0,
            "msg": "查询成功",
            "count": counts,
            "data": list(datas)
        }
    else:
        result = {
            "code": -1,
            "msg": "没有数据",
            "count": 0,
            "data": []
        }

    return HttpResponse(json.dumps(result, cls=ComplexEncoder), content_type="application/json")


def authorization_page(request):
    """店铺授权页面"""
    developerinfo = {
        "developerName": 'xxxxxxxxxx',  # 开发者名称
        "developerId": 'yyyyyyyyyy',  # 开发者id
    }
    return render(request, "authorization_page.html", {'developerinfo': developerinfo})


@csrf_exempt
def sure_authorization(request):
    """确认店铺授权"""
    site = request.POST.get('site', '')
    sellerid = request.POST.get('sellerid', '')
    auth_token = request.POST.get('auth_token', '')
    shop_name = request.POST.get('shop_name', '')
    result = {
        "code": '-1',
        "message": 'error'
    }
    if site and sellerid and auth_token and shop_name:
        param = {
            "userid": request.user.id,
            "shopname": shop_name,
            "sellerid": sellerid,
            "token": auth_token,
            "site": site,
            "status": "0",  # 默认状态授权中
            "authorizationd_datetime": datetime.datetime.now()
        }
        try:
            StoreInfo.objects.create(**param)
        except:
            pass
        else:
            result["code"] = '1'
            result["message"] = "success"
    return HttpResponse(json.dumps(result))


def damaged_lost(request):
    # 损坏丢失页面
    menu = get_menu(request)
    return render(request, "damaged_lost.html", {"menu": menu})


def show_damaged_lost_case_mode(request):
    """
    展示损坏丢失case模板
    :param request:
    :return:
    """
    from clients.models import AmazonFbaReimbursementStatistics, AmazonFbaInventoryAdjustments, AmazonFbaReimbursements
    data_id = request.GET.get('data_id', '')

    try:
        statistics_obj = AmazonFbaReimbursementStatistics.objects.get(pk=data_id)

        inventory_damaged = abs(statistics_obj.inventory_damaged)
        inventory_misplaced = abs(statistics_obj.inventory_misplaced)
        reimbursed_need = abs(statistics_obj.reimbursed_need)
        f_total = statistics_obj.inventory_found + statistics_obj.reimbursed_total_quantity
        adjustment_objs = AmazonFbaInventoryAdjustments.objects.filter(userid=statistics_obj.userid,
                                                                       shop_name=statistics_obj.shop_name,
                                                                       sku=statistics_obj.sku,
                                                                       reason__in=('M', 'E', 'F')
                                                                       ).order_by("reason", "-adjusted_date")
        adjustment_str = ''
        if adjustment_objs:
            for adjustment_obj in adjustment_objs[:10]:
                adjustment_str += adjustment_obj.transaction_item_id + ',Date:' + str(adjustment_obj.adjusted_date)[
                                                                                  :10] + '<br>&nbsp &nbsp'
        reimbursement_str = ''
        reimbursement_objs = AmazonFbaReimbursements.objects.filter(userid=statistics_obj.userid,
                                                                    shop_name=statistics_obj.shop_name,
                                                                    sku=statistics_obj.sku, reason__in=(
                'Lost_Warehouse', 'Damaged_Warehouse')).order_by("-approval_date")
        if reimbursement_objs:
            reimbursement_str = 'FBA Reimbursements ids：<br/>&nbsp &nbsp'
            for reimbursement_obj in reimbursement_objs[:10]:
                reimbursement_str += reimbursement_obj.reimbursement_id + ',Date:' + str(
                    reimbursement_obj.approval_date)[
                                                                                     :10] + '<br>&nbsp &nbsp'
        return render(request, 'show_case_model.html', {'statistics_obj': statistics_obj,
                                                        'inventory_damaged': inventory_damaged,
                                                        'inventory_misplaced': inventory_misplaced,
                                                        'reimbursed_need': reimbursed_need,
                                                        'f_total': f_total,
                                                        'adjustment_str': adjustment_str,
                                                        'reimbursement_str': reimbursement_str,
                                                        })
    except Exception as ex:
        return HttpResponse('暂无数据！')


def show_damaged_lost_info(request):
    """
    展示损坏丢失表格数据
    :param request:
    :return:
    """
    page = int(request.GET.get('page', 1))
    limit = int(request.GET.get('limit', 20))
    shop_name = str(request.GET.get('shop_name', '')).replace(" ", "")
    sku = str(request.GET.get('sku', '')).replace(" ", "")
    fnsku = str(request.GET.get('fnsku', '')).replace(" ", "")

    order_field = request.GET.get('order_field', 'refresh_time')  # 排序字段
    order_way = request.GET.get('order_way', 'desc')  # 排序方式
    order_field = '-' + order_field if order_way == 'desc' else order_field  # 默认按照刷新时间逆序

    search_info = {
        "userid__exact": request.user.id,
        "shop_name__icontains": shop_name,
        "sku__icontains": sku,
        "fnsku__icontains": fnsku,
        "display__exact": 1,
    }
    filter_info = {k: v for k, v in search_info.items() if v}
    start_index = (page - 1) * limit
    end_index = start_index + limit

    counts = AmazonFbaReimbursementStatistics.objects.filter(**filter_info).count()
    objs = AmazonFbaReimbursementStatistics.objects.filter(**filter_info).order_by(order_field)[start_index:end_index]
    if objs:
        datas = [{
            "shop_name": obj.shop_name,
            "sku": obj.sku,
            "fnsku": obj.fnsku,
            "inventory_misplaced": obj.inventory_misplaced,
            "inventory_damaged": obj.inventory_damaged,
            "inventory_found": obj.inventory_found,
            "inventory_reimbursed_total": obj.inventory_reimbursed_total,
            "reimbursed_cash_quantity": obj.reimbursed_cash_quantity,
            "reimbursed_inventory_quantity": obj.reimbursed_inventory_quantity,
            "reimbursed_total_quantity": obj.reimbursed_total_quantity,
            "reimbursed_need": obj.reimbursed_need,
            "remark": obj.remark,
            "id": obj.id,
            "case_id": obj.case_id,
            "refresh_time": obj.refresh_time
        } for obj in objs]
        result = {
            "code": 0,
            "msg": "查询成功",
            "count": counts,
            "data": list(datas)
        }
    else:
        result = {
            "code": -1,
            "msg": "没有数据",
            "count": 0,
            "data": []
        }

    return HttpResponse(json.dumps(result, cls=ComplexEncoder), content_type="application/json")


def show_refund_case(request):
    """显示申诉信息"""
    from clients.models import AmazonRefundStatisticsDetail
    data_id = request.GET.get('data_id', '')
    detail_obj = AmazonRefundStatisticsDetail.objects.filter(id=data_id).first()
    if not detail_obj:
        return HttpResponse('暂无数据！')
    else:
        seller_sku = detail_obj.seller_sku
        refund_detail = detail_obj.refund_detail
        describe_dict = {
            3: "items were destroyed without our permission",
            4: "the following units are missing from the fulfillment center",
            5: "the reimbursed amount of the items does not meet the actual value of the items",
            7: "the amount refunded by Amazon is higher than the sales amount",
            8: "items are not returned within 45 days after refund",
            9: "items are not returned within 45 days after replacement",
            10: "customer replaced the item, but Amazon refunded and ship it to the customer",
            11: "the replacement time is more than 30 days, but the restocking fee is not charged",
            12: "more items shipped than purchased.",
            13: "the FBA fee for SKU: %s should be %s" % (seller_sku, str(detail_obj.fulfillment_fee_revise)),
            14: "due to the wrong size or weight, SKU: %s was overcharged for storage" % seller_sku,
            16: "this item is overcharged warehouse storage fee due to wrong inbound time",
            17: "category fee error due to incorrect classification of item",
            18: "Amazon took part of the amount from the seller's order refund to appease the buyer, but did not reimburse the seller",
            19: "buyer's credit card fraud",
            20: "the customer return report shows that the quantity has been returned to the warehouse, but it is not actually returned"
        }
        describe_info = "We have identified that " + describe_dict.get(detail_obj.refund_type, '') if describe_dict.get(
            detail_obj.refund_type, '') else ''

        if detail_obj.refund_type == 4:
            id_info = '''shipment_id: %s''' % detail_obj.shipment_id
        elif detail_obj.refund_type in (5, 7, 8, 9, 10, 11, 12, 18, 20):
            id_info = '''amazon_order_id: %s''' % detail_obj.amazon_order_id
        elif detail_obj.refund_type in (13,):
            refund_detail = 'but the following orders of this SKU were overcharged<br> ' + refund_detail
            id_info = seller_sku = ''
        elif detail_obj.refund_type in (14,):
            id_info = seller_sku = ''
        else:
            id_info = ''
    return render(request, 'show_refund_case.html',
                  {'describe_info': describe_info, 'id_info': id_info, 'seller_sku': seller_sku,
                   'refund_detail': refund_detail})


def delivery_acceptance_diff(request):
    """
    发货接收差异
    :param request:
    :return:
    """
    menu = get_menu(request)
    return render(request, "delivery_acceptance_diff.html", {"menu": menu})


def show_delivery_acceptance_diff_info(request):
    """
    发货接收差异数据展示
    :param request:
    :return:
    """
    page = int(request.GET.get('page', 1))
    limit = int(request.GET.get('limit', 15))
    shop_name = str(request.GET.get('shop_name', '')).replace(" ", "")
    seller_sku = str(request.GET.get('seller_sku', '')).replace(" ", "")

    search_info = {
        "userid__exact": request.user.id,
        "refund_type__exact": 4,  # 发货接收差异
        "shop_name__icontains": shop_name,
        "seller_sku__icontains": seller_sku,

    }
    filter_info = {k: v for k, v in search_info.items() if v}
    start_index = (page - 1) * limit
    end_index = start_index + limit

    counts = AmazonRefundStatisticsDetail.objects.filter(**filter_info).count()
    objs = AmazonRefundStatisticsDetail.objects.filter(**filter_info)[start_index:end_index]
    if objs:
        datas = [{
            "id": obj.id,
            "shop_name": obj.shop_name,
            "seller_sku": obj.seller_sku,
            "site": obj.get_site_display(),
            "shipment_id": obj.shipment_id,
            # "fulfillment_fee_revise": obj.fulfillment_fee_revise,
            "case_id": obj.case_id,
            "deal_status": obj.get_deal_status_display(),
        } for obj in objs]
        result = {
            "code": 0,
            "msg": "查询成功",
            "count": counts,
            "data": list(datas)
        }
    else:
        result = {
            "code": -1,
            "msg": "没有数据",
            "count": 0,
            "data": []
        }

    return HttpResponse(json.dumps(result, cls=ComplexEncoder), content_type="application/json")


def refund_not_returned(request):
    """退款未退货"""
    menu = get_menu(request)
    return render(request, "refund_not_returned.html", {"menu": menu})


def show_refund_not_returned_info(request):
    """退款未退货数据展示"""
    page = int(request.GET.get('page', 1))
    limit = int(request.GET.get('limit', 15))
    shop_name = str(request.GET.get('shop_name', '')).replace(" ", "")
    seller_sku = str(request.GET.get('seller_sku', '')).replace(" ", "")
    amazon_order_id = str(request.GET.get('amazon_order_id', '')).replace(" ", "")

    search_info = {
        "userid__exact": request.user.id,
        "refund_type__exact": 8,  # 退款未退货
        "shop_name__icontains": shop_name,
        "seller_sku__icontains": seller_sku,
        "amazon_order_id__icontains": amazon_order_id,

    }
    filter_info = {k: v for k, v in search_info.items() if v}
    start_index = (page - 1) * limit
    end_index = start_index + limit

    counts = AmazonRefundStatisticsDetail.objects.filter(**filter_info).count()
    objs = AmazonRefundStatisticsDetail.objects.filter(**filter_info)[start_index:end_index]
    if objs:
        datas = [{
            "id": obj.id,
            "shop_name": obj.shop_name,
            "seller_sku": obj.seller_sku,
            "site": obj.get_site_display(),
            "amazon_order_id": obj.amazon_order_id,
            "case_id": obj.case_id,
            "deal_status": obj.get_deal_status_display(),
        } for obj in objs]
        result = {
            "code": 0,
            "msg": "查询成功",
            "count": counts,
            "data": list(datas)
        }
    else:
        result = {
            "code": -1,
            "msg": "没有数据",
            "count": 0,
            "data": []
        }

    return HttpResponse(json.dumps(result, cls=ComplexEncoder), content_type="application/json")


def exchange_not_returned(request):
    """换货未退货"""
    menu = get_menu(request)
    return render(request, "exchange_not_returned.html", {"menu": menu})


def show_exchange_not_returned_info(request):
    """换货未退数据展示"""
    page = int(request.GET.get('page', 1))
    limit = int(request.GET.get('limit', 15))
    shop_name = str(request.GET.get('shop_name', '')).replace(" ", "")
    seller_sku = str(request.GET.get('seller_sku', '')).replace(" ", "")
    amazon_order_id = str(request.GET.get('amazon_order_id', '')).replace(" ", "")

    search_info = {
        "userid__exact": request.user.id,
        "refund_type__exact": 9,  # 换货未退货
        "shop_name__icontains": shop_name,
        "seller_sku__icontains": seller_sku,
        "amazon_order_id__icontains": amazon_order_id,

    }
    filter_info = {k: v for k, v in search_info.items() if v}
    start_index = (page - 1) * limit
    end_index = start_index + limit

    counts = AmazonRefundStatisticsDetail.objects.filter(**filter_info).count()
    objs = AmazonRefundStatisticsDetail.objects.filter(**filter_info)[start_index:end_index]
    if objs:
        datas = [{
            "id": obj.id,
            "shop_name": obj.shop_name,
            "seller_sku": obj.seller_sku,
            "site": obj.get_site_display(),
            "amazon_order_id": obj.amazon_order_id,
            "case_id": obj.case_id,
            "deal_status": obj.get_deal_status_display(),
        } for obj in objs]
        result = {
            "code": 0,
            "msg": "查询成功",
            "count": counts,
            "data": list(datas)
        }
    else:
        result = {
            "code": -1,
            "msg": "没有数据",
            "count": 0,
            "data": []
        }

    return HttpResponse(json.dumps(result, cls=ComplexEncoder), content_type="application/json")


def exchange_and_refund(request):
    """换货且多退款"""
    menu = get_menu(request)
    return render(request, "exchange_and_refund.html", {"menu": menu})


def show_exchange_and_returned_info(request):
    """换货未退数据展示"""
    page = int(request.GET.get('page', 1))
    limit = int(request.GET.get('limit', 15))
    shop_name = str(request.GET.get('shop_name', '')).replace(" ", "")
    seller_sku = str(request.GET.get('seller_sku', '')).replace(" ", "")
    amazon_order_id = str(request.GET.get('amazon_order_id', '')).replace(" ", "")

    search_info = {
        "userid__exact": request.user.id,
        "refund_type__exact": 10,  # 换货且退款
        "shop_name__icontains": shop_name,
        "seller_sku__icontains": seller_sku,
        "amazon_order_id__icontains": amazon_order_id,

    }
    filter_info = {k: v for k, v in search_info.items() if v}
    start_index = (page - 1) * limit
    end_index = start_index + limit

    counts = AmazonRefundStatisticsDetail.objects.filter(**filter_info).count()
    objs = AmazonRefundStatisticsDetail.objects.filter(**filter_info)[start_index:end_index]
    if objs:
        datas = [{
            "id": obj.id,
            "shop_name": obj.shop_name,
            "seller_sku": obj.seller_sku,
            "site": obj.get_site_display(),
            "amazon_order_id": obj.amazon_order_id,
            "case_id": obj.case_id,
            "deal_status": obj.get_deal_status_display(),
        } for obj in objs]
        result = {
            "code": 0,
            "msg": "查询成功",
            "count": counts,
            "data": list(datas)
        }
    else:
        result = {
            "code": -1,
            "msg": "没有数据",
            "count": 0,
            "data": []
        }

    return HttpResponse(json.dumps(result, cls=ComplexEncoder), content_type="application/json")


def overcharge_shipping(request):
    """多收运费"""
    menu = get_menu(request)
    return render(request, "overcharge_shipping.html", {"menu": menu})


def show_overcharge_shipping_info(request):
    """多收运费数据表展示"""
    page = int(request.GET.get('page', 1))
    limit = int(request.GET.get('limit', 15))
    shop_name = str(request.GET.get('shop_name', '')).replace(" ", "")
    seller_sku = str(request.GET.get('seller_sku', '')).replace(" ", "")

    search_info = {
        "userid__exact": request.user.id,
        "refund_type__exact": 13,  # 多收运费
        "shop_name__icontains": shop_name,
        "seller_sku__icontains": seller_sku,

    }
    filter_info = {k: v for k, v in search_info.items() if v}
    start_index = (page - 1) * limit
    end_index = start_index + limit

    counts = AmazonRefundStatisticsDetail.objects.filter(**filter_info).count()
    objs = AmazonRefundStatisticsDetail.objects.filter(**filter_info)[start_index:end_index]
    if objs:
        datas = [{
            "id": obj.id,
            "shop_name": obj.shop_name,
            "seller_sku": obj.seller_sku,
            "site": obj.get_site_display(),
            "case_id": obj.case_id,
            "deal_status": obj.get_deal_status_display(),
            "refund_detail": str(obj.refund_detail),
            "id": obj.id
        } for obj in objs]
        result = {
            "code": 0,
            "msg": "查询成功",
            "count": counts,
            "data": list(datas)
        }
    else:
        result = {
            "code": -1,
            "msg": "没有数据",
            "count": 0,
            "data": []
        }

    return HttpResponse(json.dumps(result, cls=ComplexEncoder), content_type="application/json")


def overcharge_storage_fees(request):
    """多收仓储费"""
    menu = get_menu(request)
    return render(request, "overcharge_storage_fees.html", {"menu": menu})


def show_overcharge_storage_fees_info(request):
    """多收仓储费数据展示"""
    page = int(request.GET.get('page', 1))
    limit = int(request.GET.get('limit', 15))
    shop_name = str(request.GET.get('shop_name', '')).replace(" ", "")
    seller_sku = str(request.GET.get('seller_sku', '')).replace(" ", "")

    search_info = {
        "userid__exact": request.user.id,
        "refund_type__exact": 14,  # 多收仓储费
        "shop_name__icontains": shop_name,
        "seller_sku__icontains": seller_sku,

    }
    filter_info = {k: v for k, v in search_info.items() if v}
    start_index = (page - 1) * limit
    end_index = start_index + limit

    counts = AmazonRefundStatisticsDetail.objects.filter(**filter_info).count()
    objs = AmazonRefundStatisticsDetail.objects.filter(**filter_info)[start_index:end_index]
    if objs:
        datas = [{
            "id": obj.id,
            "shop_name": obj.shop_name,
            "seller_sku": obj.seller_sku,
            "site": obj.get_site_display(),
            "case_id": obj.case_id,
            "deal_status": obj.get_deal_status_display(),
            "refund_detail": str(obj.refund_detail),
            "id": obj.id
        } for obj in objs]
        result = {
            "code": 0,
            "msg": "查询成功",
            "count": counts,
            "data": list(datas)
        }
    else:
        result = {
            "code": -1,
            "msg": "没有数据",
            "count": 0,
            "data": []
        }

    return HttpResponse(json.dumps(result, cls=ComplexEncoder), content_type="application/json")


@csrf_exempt
def update_caseid(request):
    """回填caseid"""
    result = {"code": 0, "message": "error"}
    try:
        datas = json.loads(request.POST.get('datas', ''))
        id, case_id = datas['id'], datas['case_id']
        AmazonRefundStatisticsDetail.objects.filter(pk=id).update(case_id=case_id,
                                                                  update_case_id_datetime=datetime.datetime.now())
        result = {"code": 1, "message": "success"}
    except:
        pass
    return HttpResponse(json.dumps(result))


@csrf_exempt
def update_damaged_lost_caseid(request):
    """回填caseid"""
    result = {"code": 0, "message": "error"}
    try:
        datas = json.loads(request.POST.get('datas', ''))
        id, case_id = datas['id'], datas['case_id']
        AmazonFbaReimbursementStatistics.objects.filter(pk=id).update(case_id=case_id,
                                                                      update_case_id_datetime=datetime.datetime.now())
        result = {"code": 1, "message": "success"}
    except:
        pass
    return HttpResponse(json.dumps(result))
